//
//  HMSportTrackingLine.m
//  黑马行
//
//  Created by 宇宙执政 on 16/9/20.
//  Copyright © 2016年 yujianbinMAC. All rights reserved.
//

#import "HMSportTrackingLine.h"
#import "HMSportPolyline.h"

@implementation HMSportTrackingLine

- (instancetype)initWithStartLocation:(CLLocation *)startLocation endLocation:(CLLocation *)endLocation{
    
    if (self = [super init]) {
        _startLocation = startLocation;
        _endLocation = endLocation;
    }
    
    return self;
}

//小米：“我出5”，苹果：“我出7”，华为：“我出9”，三星：“我炸”，其他厂商：“要不起”

-(HMSportPolyline *)polyline{
    
    CLLocationCoordinate2D coords[2];
    coords[0] = _startLocation.coordinate;
    coords[1] = _endLocation.coordinate;
    
    // 设置放大比例因子
    CGFloat factor = 8;
    CGFloat red = factor * self.speed / 255.0;
    UIColor *color = [UIColor colorWithRed:red green:1 blue:0 alpha:1];
    
    NSLog(@"平均速度 %f km/h",self.speed);
    
    return [HMSportPolyline polylineWithCoordinates:coords count:2 color:color];
    
}

-(double)speed{
    
    return (_startLocation.speed + _endLocation.speed) * 0.5 * 3.6;
}

-(NSTimeInterval)time{
    
    return [_endLocation.timestamp timeIntervalSinceDate:_startLocation.timestamp];
}

-(double)distance{
    
    return [_endLocation distanceFromLocation:_startLocation] * 0.001;
    
}

@end
